﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HNCDataSetTableAdapters;
using System.Data.SqlClient;
using System.Configuration;

public partial class UserControl_search_result : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadResult();
        }
    }

    public void loadResult()
    {
        string keyword = HttpContext.Current.Request.RequestContext.RouteData.Values["str"].ToString();
        if (keyword =="all")
        {
            keyword = "";
        }
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["HNC_DBConnectionString"].ConnectionString);
        con.Open();
        string GetResult = @"SELECT Products.ProductID, Products.Code, Products.Title, Products.Title_en, Products.Description, Products.Description_en, Products.[Content], Products.Content_en, 
                         Products.Image, Products.Link, Products.VideoUrl, Products.Price, Products.PriceSale, Products.CateID, Products.AddDate, Products.Editdate, Products.AddBy, 
                         Products.New, Products.Vip, Products.Sale, Products.MetaTitle, Products.MetaDescription, Products.MetaKeywork, Products.MetaRobots, Products.[Order], 
                         Products.Status, Products.[Delete], Category.ParentID, Category.Title AS Expr1, Category.Title_en AS Expr2
                         FROM Products INNER JOIN Category ON Products.CateID = Category.CateID
                        WHERE (Products.[Delete] = 0) AND (Category.ParentID = 3) AND Products.Title LIKE '%" + keyword + "%' ORDER BY Products.Editdate DESC";
        
        SqlDataAdapter daCustomer = new SqlDataAdapter(GetResult, con);
        DataTable dtResult = new DataTable();
        daCustomer.Fill(dtResult);

        DataView dv = (DataView)dtResult.DefaultView;
        CollectionPager1.PageSize = 100;
        CollectionPager1.DataSource = dv;
        CollectionPager1.BindToControl = rptResult;
        rptResult.DataSource = CollectionPager1.DataSourcePaged;
        rptResult.DataBind();
        con.Close();
    }
}